class Band

This class contains the behaviours and attributes for a band of humans. Bands follow simple steps of seeking out a new patch, consuming resources and procreating.

Attributes

num_bands_split[R]
num_born[R]
num_died[R]
size[R]

Public Class Methods

new(scape, patch, conf) click to toggle source

Create a new band with a scape and patch that it belongs and a configuration.

# File lib/band.rb, line 22
def initialize(scape, patch, conf)
  @scape = scape
  @current_patch = patch
  @size = size

  @conf = conf # For passing on to children
  # Things we are interested from the passed in conf
  stealables = [:size, :visibility, :search_speed, :search_radius, :search_cost, :handle_cost, :energy_requirement, :birth_chance, :resource_preference]
  stealables.each{|s|self.instance_variable_set("@#{s.to_s}".to_sym, conf[s.to_s])}
  @resource_preference = hash_intern(@resource_preference)
  # This is for logging
  @num_born = 0
  @num_died = 0
  @num_bands_split = 0

  # A precomputed value to make nar computations faster
  @patch_search = (@current_patch.area / (@search_speed * @search_radius * 2))

  if !patch.join
    warn "Warning: Could not join the patch given in the parameter"
    shuffle_about_this_cold_hard_earth
  end
end

Public Instance Methods

do_time_step() click to toggle source

Performs one iteration/epoch, completing each of the steps in the basic behaviour of a band. This is the entry point to getting a band to do something.

# File lib/band.rb, line 49
def do_time_step
  shuffle_about_this_cold_hard_earth
  consume
  procreate
end
to_s() click to toggle source

Provides a string representation of the Band. Used for logging.

# File lib/band.rb, line 233
  def to_s
    "Band (id:#{object_id}) { Patch id: #{@current_patch.object_id} | Size: #{@size} | \
Born/died: #{@num_born}/#{@num_died} | Split: #{@num_bands_split} }"
  end